package com.capgemini.diabeo;

import com.capgemini.diabeo.settings.SettingsActivity;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		final Context ctx = this.getApplicationContext();

		Button btn_repas = (Button) findViewById(R.id.repas);
		btn_repas.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(ctx, MealChoice.class);
				startActivity(i);
			}
		});
		
		Button btn_plats_liste = (Button) findViewById(R.id.plat_liste);
		btn_plats_liste.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				MealChoice.mealChoice = "autre";
				Intent i = new Intent(ctx, AddDishListActivity.class);
				startActivity(i);
			}
		});
		
		Button btn_settings_glucose = (Button) findViewById(R.id.settings_glucose);
		btn_settings_glucose.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent i = new Intent(ctx, SettingsActivity.class);
				startActivity(i);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpTo(this, new Intent(this,
					AddDishListActivity.class));
					return true;
		case R.id.action_settings:
			Intent i = new Intent(this, SettingsActivity.class);
			startActivity(i);
			break;
		default:
			break;
		}

		return true;
	} 
}
